module.exports = function (sequelize) {
    var model = sequelize.define("role", {
            "roleCode": {
                type: sequelize.DataTypes.STRING(50),
                allowNull: false,
                primaryKey: true,
                comment: "角色编号"
            },
            "roleName": {
                type: sequelize.DataTypes.STRING(50),
                allowNull: false,
                comment: "角色名称"
            },
            "roleSort": {
                type: sequelize.DataTypes.INTEGER(5),
                allowNull: true,
                defaultValue: 0,
                comment: "角色排序"
            },
            "isActive": {
                type: sequelize.DataTypes.CHAR(1),
                allowNull: true,
                defaultValue: 1,
                comment: "角色是否启用"
            }
        },
        {
            "tableName": "role"
        });

    model.initRelation = function () {
        model.belongsTo(db.models.trueFalse, {foreignKey: "isActive", constraints: false});
        model.hasMany(db.models.roleForResources, {as:"roleForResourcesObj",foreignKey: 'roleCode', constraints: false});
        model.hasMany(db.models.userForRole, {foreignKey: 'roleCode', constraints: false});
    }

    model.initData = new Array();
    model.initData.push({
        roleCode: "ADMIN",
        roleName: "管理员",
        roleSort: 0,
        isActive: "1"
    });
}